#include "player.h"
#include"monster.h"
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include "Prop.h"
#include "Scene.h"
#include <DynamicArray.h>
#include <StdFile.h>
void Save(Player *p,DArray *ms);
void SaveInterface();
bool load(Player *p,DArray *ms);
void ClearMyStringList(MyStrList *list);

void InitPlayer(Player *p)
{
    p->HP=100;
    p->MAXHP=100;
    p->attack=8;
    p->defence=1;
    p->x=0;
    p->y=0;
    p->symbol ="  👴 ";
    p->exp=0;
    p->level = 1;
    p->Gold = 5000;
 

    InitDynamicArray(&p->backpack);
    p->w = NULL;
    p->d = NULL;
    p->m = NULL;
}

void PrintPlayer(Player *p)
{
    printf("玩家状态👤:\n等级ℹ️:%d 经验值📗:%d 金币💰:%d\n生命值💗:%d 攻击力🗡️:%d 防御力🛡:%d\n",p->level,p->exp,p->Gold,p->HP,p->attack,p->defence);
    if(p->w!=NULL)
    printf("当前武器:[%s]\n",p->w->name.string);
    else
    printf("当前武器:[👊沙包大的拳头]\n");
    if(p->d!=NULL)
    printf("当前防具:[%s]\n",p->d->name.string);
    else
    printf("当前防具:[无]\n");
}

void PlayerMove(Player *p,char* (*map)[MAPSIZE],DArray *ms)
{
    map[p->x][p->y]="  *  ";
    char choice=0;
    printf("请选择玩家下一步操作(W,A,S,D,P(打开商店🛒),B(打开背包🎒),C(记录存档📥),L(读取存档📤)):");
    scanf(" %c",&choice);
    printf("\n");
    switch(choice)
    {
        case 'W':   
            p->x--;
            if(p->x < 0)
                p->x=0;
            break;
        case 'A':   
            p->y--;
            if(p->y < 0)
                p->y=0;
            break;
        case 'S':   
            p->x++;
            if(p->x>=MAPSIZE)
                p->x=MAPSIZE-1;
            break;
        case 'D':   
            p->y++;
            if(p->y>=MAPSIZE)
                p->y=MAPSIZE-1;
            break;
        case 'P':  
            ShopInterface(p);
            break;
        case 'B':  
            ShowBackpack(p);
            break;
        case 'C':
            Save(p,ms);
            break;
        case'L':
            load(p,ms);
            break;
        default:    
            break;
    }
    
    map[p->x][p->y]=p->symbol;
}

void LevelUp(Player *p)
{
    if(p->exp >=50)
    {
        p->exp-=50;
        p->level+=1;
        printf("恭喜玩家升到%d级!🆙\n",p->level);
        p->MAXHP+=10;
        p->HP = p->MAXHP;
        p->attack += p->attack*0.2;
        p->defence+=1;
    }
    
}

static int count=0;

void ShowProp(void* ptr)
{
    count++;
    Prop *pro=(Prop*)ptr;
    if(pro->type == WEAPON)
    {
        Weapon *w = (Weapon*)pro->ptr;
        printf("%d.名称:%s",count,w->name.string);
        printf("[攻击力🗡 :%d]\n",w->attack);
    }
    if(pro->type == DEFENCE)
    {
        Defence *d = (Defence*)pro->ptr;
        printf("%d.名称:%s",count,d->name.string);
        printf("[防御力🛡 :%d]\n",d->defence);
    }
    if(pro->type == MEDICAMENT)
    {
        Medicament *m = (Medicament*)pro->ptr;
        printf("%d.名称:%s",count,m->name.string);
        printf("[恢复值💕:%d]\n",m->HP);
    }

}

bool SortByPropType(void* ptr1,void* ptr2)
{
    Prop* p1=(Prop*)ptr1;
    Prop* p2=(Prop*)ptr2;
    if(p1->type > p2->type)
    {
        return true;
    }
    else
    {
        return false;
    }
}

int GetInput()
{
    int choice = 0;
    scanf("%d",&choice);
    while (getchar()!='\n');
    return choice;
}

void UseProp(Player *p,int index)
{

    if(index <= 0 || index > p->backpack.len)
    {
        printf("未找到该编号的道具,请重新进行选择!\n");
        sleep(1);
        return;
    }
                    //第n个道具
    Prop *pro = p->backpack.dp[index-1];
    if(pro->type==WEAPON)
    {
        Weapon *w =(Weapon *)pro->ptr;
        system("clear");
        printf("请问是否要装备[%s]?\n请选择:\n",w->name.string);
        printf("1.是\n2.否\n");
        int choice = GetInput();
        if(choice==1)
            {
                if (p->w==NULL)
                {
                    printf("已成功装备武器[%s]!\n",w->name.string);
                    sleep(1);
                }
                else
                {
                    p->backpack.InsertArrayTail(&p->backpack,CreateProp(WEAPON,p->w));
                    system("clear");
                    printf("武器[%s]已卸下,已装备新武器[%s]\n",p->w->name.string,w->name.string);
                    p->attack-=p->w->attack;
                    sleep(1);
                    system("clear");
                }
                p->w = w;
                p->attack+=p->w->attack;
                p->backpack.RemoveByIndex(&p->backpack,index-1,NULL);
                free(pro);
            }

    }        
    
    if(pro->type==DEFENCE)
    {
        Defence *d =(Defence *)pro->ptr;
        system("clear");
        printf("请问是否要装备[%s]?\n请选择:\n",d->name.string);
        printf("1.是\n2.否\n");
        int choice = GetInput();
        if(choice==1)
            {
                if (p->d==NULL)
                {
                    printf("已成功装备防具[%s]!\n",d->name.string);
                    sleep(1);
                     
                }
                else
                {
                    p->backpack.InsertArrayTail(&p->backpack,CreateProp(DEFENCE,p->d));
                    system("clear");
                    printf("防具[%s]已卸下,已装备新防具[%s]\n",p->d->name.string,d->name.string);
                    sleep(1);
                    system("clear");
                }
                p->d = d;
                p->defence+=p->d->defence;
                p->backpack.RemoveByIndex(&p->backpack,index-1,NULL);
                free(pro);
            }
        
        
        
        else
            return;


    }

    if(pro->type==MEDICAMENT)
    {
        Medicament *m = (Medicament *)pro->ptr;
        system("clear");
        printf("请问是否要服用[%s]?\n当前生命值:(%d/%d)\n请选择:\n",m->name.string,p->HP,p->MAXHP);
        printf("1.是\n2.否\n");
        int choice = GetInput();
        if(choice==1)
            {
                
                printf("成功服用[%s],恢复了%d点HP💕。(%d/%d)\n",m->name.string,m->HP,p->HP,p->MAXHP);
                
                p->m=m;
                if(p->HP+p->m->HP<=p->MAXHP)                                //恢复生命溢出
                p->HP+=p->m->HP;
                
                else
                p->HP=p->MAXHP;
                p->m = NULL;
                p->backpack.RemoveByIndex(&p->backpack,index-1,NULL);
                sleep(1);
            }
    }
        else
        return;
              
}

void ShowBackpack(Player *p)
{
    while(1)
    {
        system("clear");
        if(p->backpack.len==0)
        {
            printf("背包空空如也...\n");
            printf("\n");
            printf("按“Q”退出背包\n");  
        }
        else
        {
        printf("============================背包==============================\n");
        p->backpack.Sort(&p->backpack,SortByPropType);
        count = 0;
        p->backpack.DisplayDynamicArray(&p->backpack,ShowProp); 
        count = 0; 
        printf("\n");
        printf("请选择道具编号进行操作 或 按“Q”退出背包\n");

        }

        char choice[10] ={0};
        scanf("%s",choice);
        while(getchar()!='\n');
        if(strcmp(choice,"Q")==0)
        {
            return;
        }
        else
        {
            UseProp(p,atoi(choice));
        }
    }
}

MyStr PlayerToString(Player *p)
{
    char str[2048]={0};
    sprintf(str,"%d %d %d %d %d %d %d %d %d %s\n",p->HP,p->MAXHP,p->attack,p->defence,p->x,p->y,p->level,p->exp,p->Gold,p->symbol);
    printf("%s\n",str);
    if(p->w!=NULL)
    {
        char weapon[100]={0};
        sprintf(weapon,"%s %d %d\n",p->w->name.string,p->w->attack,p->w->effect); 
        strcat(str,weapon);       
    }
    else
    {   
        char weapon[100]={0};
        sprintf(weapon,".\n"); 
        strcat(str,weapon); 
    }

    if(p->d!=NULL)
    {
        char defence[100]={0};
        sprintf(defence," %s %d %d\n",p->d->name.string,p->d->defence,p->d->effect); 
        strcat(str,defence);       
    }
    else
    {   
        char defence[100]={0};
        sprintf(defence,".\n"); 
        strcat(str,defence); 
    }

   // strcat(str,"背包:\n");
    for(int i=0;i<p->backpack.len;i++)
    {
        char prop[100]={0};
        Prop *pro=p->backpack.dp[i];
        if(pro->type==WEAPON)
        {
            MyStr s = WeaponToString((Weapon*)pro->ptr);
            strcat(str,s.string);
            ClearString(&s);
        }
        if(pro->type==DEFENCE)
        {
            MyStr s = DefenceToString((Defence*)pro->ptr);
            strcat(str,s.string);
            ClearString(&s);
        }
        if(pro->type==MEDICAMENT)
        {
            MyStr s = MedicamentToString((Medicament*)pro->ptr);
            strcat(str,s.string);
            ClearString(&s);
        }
    }
    strcat(str,".");
    return GetString(str);
}

void StringToPlayer(MyStrList* player,Player* p)
{
    InitPlayer(p);
    int effect=0;

    scanf(player->stringlist[0].string,"%d %d %d %d %d %d %d %d %d %s",&p->HP,&p->MAXHP,&p->attack,&p->defence,&p->x,&p->y,&p->level,&p->exp,&p->Gold,p->symbol);
    sleep(2);
    if(player->stringlist[1].len!=1)
    {
        Weapon* w=CreateWeapon(" ",0,0);
        ResizeString(&w->name,32); 
        sscanf(player->stringlist[1].string,"%s %d %d",w->name.string,&w->attack,(int*)&w->effect);
        p->w=w;
    }
   
    if(player->stringlist[2].len!=1)
    {
        Defence *d=CreateDefence(" ",0,0);
        ResizeString(&d->name,32);
        sscanf(player->stringlist[2].string,"%s %d %d",d->name.string,&d->defence,(int*)&d->effect);
        p->d=d;
    }
    
      for(int i=3;player->stringlist[i].len!=1;i++)
    {
        int TempType = 0;
        char TempName[20] = {0};
        int TempValue = 0;
        int TempId = 0;
        int TempEffect = 0;
        sscanf(player->stringlist[i].string," %d %s %d %d",&TempType,TempName,&TempValue,&TempEffect);
        if(TempType == WEAPON)
        {
            p->backpack.InsertArrayTail(&p->backpack,CreateProp(WEAPON,CreateWeapon(TempName,TempValue,TempEffect)));
        }
        if(TempType == DEFENCE)
        {
            p->backpack.InsertArrayTail(&p->backpack,CreateProp(DEFENCE,CreateDefence(TempName,TempValue,TempEffect)));
        }
        if(TempType == MEDICAMENT)
        {
            p->backpack.InsertArrayTail(&p->backpack,CreateProp(MEDICAMENT,CreateMedicament(TempName,TempValue,TempEffect)));
        }
    }




}
void StringToMonster(MyStrList* monster,DArray* ms);

bool load(Player*p ,DArray *ms)
{
    system("clear");
    SaveInterface();
    printf("请选择你的存档:\n");
    printf("按“1”读取存档一\n");
    printf("按“2”读取存档二\n");
    printf("按“3”读取存档三\n");
    printf("按“4”读取存档四\n");
    printf("按“5”退出游戏\n");
    int choice=0;
    scanf(" %d",&choice);
    printf("\n");
    switch(choice)
    {
        case 1:
            {
            MyStrList player1;
            InitMyStringList(&player1);
            FILE* fp1;
            fp1 = fopen("/home/lvguanzhong/桌面/suqian/1122/存档库/存档一p","r");
            if(fp1 == NULL)
            {
                printf("未读取到该人物存档!\n");
                sleep(2);
                break;
            }
            player1 = GetlineFromFile("/home/lvguanzhong/桌面/suqian/1122/存档库/存档一p");
            StringToPlayer(&player1,p);
            
            ClearMyStringList(&player1);

            MyStrList monster1;
            InitMyStringList(&monster1);
            FILE* fm1;
            fm1 = fopen("/home/lvguanzhong/桌面/suqian/1122/存档库/存档一m","r");
            if(fm1 == NULL)
            {
                printf("未读取到怪物存档1!\n");
                sleep(2); 
                break;
            }

            monster1 = GetlineFromFile("/home/lvguanzhong/桌面/suqian/1122/存档库/存档一m");
            StringToMonster(&monster1,ms);
            ClearMyStringList(&monster1);
            return true;
            break;
            }
       case 2:
            {
            MyStrList player2;
            InitMyStringList(&player2);
            FILE* fp2;
            fp2 = fopen("/home/lvguanzhong/桌面/suqian/1122/存档库/存档二p","r");
            if(fp2 == NULL)
            {
                printf("未读取到该人物存档!\n");
                sleep(2);
                break;
            }
            player2 = GetlineFromFile("/home/lvguanzhong/桌面/suqian/1122/存档库/存档二p");
            StringToPlayer(&player2,p);
            
            ClearMyStringList(&player2);

            MyStrList monster2;
            InitMyStringList(&monster2);
            FILE* fm2;
            fm2 = fopen("/home/lvguanzhong/桌面/suqian/1122/存档库/存档二m","r");
            if(fm2 == NULL)
            {
                printf("未读取到怪物存档1!\n");
                sleep(2); 
                break;
            }

            monster2 = GetlineFromFile("/home/lvguanzhong/桌面/suqian/1122/存档库/存档二m");
            StringToMonster(&monster2,ms);
            ClearMyStringList(&monster2);
            return true;
            break;
        }    
        case 3:
            {
            MyStrList player3;
            InitMyStringList(&player3);
            FILE* fp3;
            fp3 = fopen("/home/lvguanzhong/桌面/suqian/1122/存档库/存档三p","r");
            if(fp3 == NULL)
            {
                printf("未读取到该人物存档!\n");
                sleep(2);
                break;
            }
            player3 = GetlineFromFile("/home/lvguanzhong/桌面/suqian/1122/存档库/存档三p");
            StringToPlayer(&player3,p);
            
            ClearMyStringList(&player3);

            MyStrList monster3;
            InitMyStringList(&monster3);
            FILE* fm3;
            fm3 = fopen("/home/lvguanzhong/桌面/suqian/1122/存档库/存档三m","r");
            if(fm3 == NULL)
            {
                printf("未读取到怪物存档!\n");
                sleep(2); 
                break;
            }

            monster3 = GetlineFromFile("/home/lvguanzhong/桌面/suqian/1122/存档库/存档三m");
            StringToMonster(&monster3,ms);
            ClearMyStringList(&monster3);
            return true;
            break;
        }    
        case 4:
            {
            MyStrList player4;
            InitMyStringList(&player4);
            FILE* fp4;
            fp4 = fopen("/home/lvguanzhong/桌面/suqian/1122/存档库/存档四p","r");
            if(fp4 == NULL)
            {
                printf("未读取到该人物存档!\n");
                sleep(2);
                break;
            }
            player4 = GetlineFromFile("/home/lvguanzhong/桌面/suqian/1122/存档库/存档四p");
            StringToPlayer(&player4,p);
            
            ClearMyStringList(&player4);

            MyStrList monster4;
            InitMyStringList(&monster4);
            FILE* fm4;
            fm4 = fopen("/home/lvguanzhong/桌面/suqian/1122/存档库/存档四m","r");
            if(fm4 == NULL)
            {
                printf("未读取到怪物存档!\n");
                sleep(2); 
                break;
            }

            monster4 = GetlineFromFile("/home/lvguanzhong/桌面/suqian/1122/存档库/存档四m");
            StringToMonster(&monster4,ms);
            ClearMyStringList(&monster4);
            return true;
            break;
        }    
    default:
    break;
        
    }
}


void ShopInterface(Player *p)
{
 while(1){
    {
    system("clear");
    printf("===================欢迎来到黑心商人的良心商店===================\n");
    printf("========================看看需要买点什么========================\n");
    printf("1.🗡 你贩剑嘛？\n");
    printf("2.🛡 有防具吗？\n");
    printf("3.💊有药嘛？\n");
    printf("4.没事，我就随便看看。\n");
    }
    int choice =0;
    scanf("%d",&choice);
    switch(choice)
    {
        {//买刀
            case 1:  
            {                           
                system("clear"); 
                printf("还真让你赶上了，大力本前两天刚打了几把刀，看看要哪把？\n");
                printf("\n");
                printf("1.🔪水果刀(+5攻击力)------------------------$:20\n");
                printf("武器效果：平平无奇，纯纯的物理伤害。\n");
                printf("\n");
                printf("2.🪓消防斧(+8攻击力,攻击施加感染效果)--------$:25\n");
                printf("道具描述:我可不想在战斗时误伤我自己。\n");
                printf("\n");
                printf("3.🔮魔法球(+10攻击力,攻击窃取生命)------------$:35\n");
                printf("道具描述:一个晶莹剔透的球，似乎有某种神奇的魔力。\n");
                printf("\n");
                printf("4.🔫鹅城县长张牧之的枪--------------------$:99\n");
                printf("道具描述:”虎扑评分:9.9分.神中神” 时代变了，大人。\n");
                printf("\n");
                printf("5.没事，我就随便看看。\n");
            }
                int weaponchoice = 0;
                scanf("%d",&weaponchoice);
                switch(weaponchoice)
                {
                    case 1:     //🔪水果刀
                        if(p->Gold<20)
                    {   
                        system("clear");
                        printf("你看了看价格，又摸了摸兜里的金币，想想还是算了吧。\n");
                        sleep(2);
                        system("clear");
                        break;
                    }
                    else
                    {
                    p->Gold-=20;
                    p->backpack.InsertArrayTail(&p->backpack,CreateProp(WEAPON,CreateWeapon("水果刀",5,-1)));
                    system("clear"); 
                    printf("你花费20金币购买了[🔪水果刀],似乎用起来很趁手，迫不及待地想找个怪物试试。\n");
                    printf("你挥了挥刀,露出了满意的笑容:“一窝Q~”\n");
                    printf("你算了一下，兜里还有%d个金币。\n",p->Gold);
                    printf("\n");
                    sleep(2);
                    system("clear");
                    }
                    break;

                     case 2:     //破伤风之剑                        
                        if(p->Gold<25)
                        {   
                            system("clear");
                            printf("你看了看价格，又摸了摸兜里的金币，想想还是算了吧。\n");
                            sleep(2);
                            system("clear");
                        break;
                        }
                    else
                        {
                        p->Gold-=25;
                        p->backpack.InsertArrayTail(&p->backpack,CreateProp(WEAPON,CreateWeapon("消防斧",8,-1)));
                        system("clear");
                        printf("你花费25金币购买了[🪓消防斧],用起来很趁手，迫不及待地想找个怪物试刀。\n");
                        printf("你挥了挥刀,露出了满意的笑容:“一窝Q~”\n");
                        printf("你算了一下，兜里还有%d个金币。\n",p->Gold);
                        printf("\n");
                        sleep(2);
                        system("clear");
                        }
                    break;

                    case 3:                             
                        if(p->Gold<35)
                        {   
                        system("clear");
                        printf("你看了看价格，又摸了摸兜里的金币，想想还是算了吧。\n");
                        sleep(2);
                        system("clear");
                        break;
                        }
                    else
                        {
                        p->Gold-=35;
                        p->backpack.InsertArrayTail(&p->backpack,CreateProp(WEAPON,CreateWeapon("魔法球",10,-1)));
                        system("clear");
                        printf("你花35金币购买了[🔮魔法球],你盯着魔法球看到几乎入迷。\n");
                        printf("太美丽了,家人们。\n");
                        printf("你算了一下，兜里还有%d个金币。\n",p->Gold);
                        printf("\n");
                        sleep(2);
                        system("clear");
                        }
                    break;
                    
                    case 4:                             
                        if(p->Gold<99)
                        {   
                        system("clear");
                        printf("你看了看价格，又摸了摸兜里的金币，想想还是算了吧。\n");
                        sleep(2);
                        system("clear");
                        break;
                        }
                    else
                        {
                        p->Gold-=99;
                        p->backpack.InsertArrayTail(&p->backpack,CreateProp(WEAPON,CreateWeapon("鹅城县长张牧之的枪",30,-1)));
                        system("clear");
                        printf("你花99金币购买了[🔫鹅城县长张牧之的枪],热武器的时代就要来临了。\n");
                        printf("你好好检视了一番,嘴里念念有词地说些什么：“公平!公平!还是他妈的公平！”\n");
                        printf("你算了一下，兜里还有%d个金币。\n",p->Gold);
                        printf("\n");
                        sleep(2);
                        system("clear");
                        }
                    break;

                    case 5:
                        system("clear");
                    break;

                    default:
                        system("clear");
                    break;
                    }  
                weaponchoice=0; 
                break;
        }

        {//买甲
            case 2: 
            {                            
                system("clear"); 
                printf("还真让你赶上了,我刚进的的好货，看看怎么样？\n");
                printf("\n");
                printf("1.🧥外套(+3防御力)---------------------$:20\n");
                printf("道具描述:普普通通的一件外套，没什么特殊的。\n");
                printf("\n");
                printf("2.🎭舞会假面(+5防御力)--------------------$:25\n");
                printf("道具描述: 安全来于警惕 事故出于麻痹。\n");
                printf("\n");
                printf("3.🎃南瓜头(+10防御力)-------------------$:35\n");
                printf("道具描述:怎么？这个世界上存在末影人么?\n");
                printf("\n");       
                printf("4.🧣女朋友织的围巾----------------------$:99\n");
                printf("道具描述:香香软软~\n");
                printf("\n");
                printf("5.没事，我就随便看看。\n");
            }
                int armorchoice = 0;
                scanf("%d",&armorchoice);
                switch(armorchoice)
                {
                    case 1:     //外套
                        if(p->Gold<18)
                            {   
                            system("clear");
                            printf("你看了看价格，又摸了摸兜里的金币，想想还是算了吧。\n");
                            break;
                            }
                        else
                            {
                            p->Gold-=18;
                            p->backpack.InsertArrayTail(&p->backpack,CreateProp(DEFENCE,CreateDefence("外套",3,-1)));
                            system("clear"); 
                            printf("你花费18金币购买了一件[🧥外套],很修身,感觉自己都变帅了。\n");
                            printf("你算了一下，兜里还有%d个金币。\n",p->Gold);
                            printf("\n");
                            sleep(2);
                            system("clear");
                            } 
                        break;

                    case 2:    //舞会假面 
                        if(p->Gold<25)
                            {   
                            system("clear");
                            printf("你看了看价格，又摸了摸兜里的金币，想想还是算了吧。\n");
                            break;
                            }
                        else
                            {
                            p->Gold-=25;
                            p->backpack.InsertArrayTail(&p->backpack,CreateProp(DEFENCE,CreateDefence("舞会假面",5,-1)));
                            system("clear"); 
                            printf("你花费25金币购买了[🎭舞会假面],大小正合适。\n");
                            printf("你算了一下，兜里还有%d个金币。\n",p->Gold);
                            printf("\n");
                            sleep(2);
                            system("clear");
                            }
                        break;
                
                    case 3:     //🎃南瓜头
                        if(p->Gold<25)
                            {   
                            system("clear");
                            printf("你看了看价格，又摸了摸兜里的金币，想想还是算了吧。\n");
                            break;
                            }
                        else
                            {
                            p->Gold-=25;
                            p->backpack.InsertArrayTail(&p->backpack,CreateProp(DEFENCE,CreateDefence("南瓜头",5,-1)));
                            system("clear"); 
                            printf("你花费25金币购买了[🎃南瓜头]。\n");
                            printf("你算了一下，兜里还有%d个金币。\n",p->Gold);
                            printf("\n");
                            sleep(2);
                            system("clear");
                            }
                        break;
                    
                    case 4:     //女朋友织的围巾
                        if(p->Gold<99)
                            {
                            system("clear");
                            printf("你看了看价格，又摸了摸兜里的金币，想想还是算了吧。\n");
                            break;
                            }
                        else
                            {
                            p->Gold-=99;
                            p->backpack.InsertArrayTail(&p->backpack,CreateProp(DEFENCE,CreateDefence("女朋友织的围巾",20,-1)));
                            system("clear"); 
                            printf("你花费99金币购买了[🧣女朋友织的围巾],香香软软,感觉心里暖暖的。\n");
                            printf("你算了一下，兜里还有%d个金币。\n",p->Gold);
                            printf("\n");
                            sleep(2);
                            system("clear");
                            }
                        break;
                    
                    case 5:
                        system("clear");
                        break;
                    default:
                        system("clear");
                        break;
                }
                armorchoice=0; 
                break;
        }
    
            {//买药
            case 3:  
            {                           
                system("clear"); 
                printf("还真让你赶上了,我刚进的的好货，看看怎么样？\n");
                printf("\n");
                printf("1.🍞奇怪的面包----------------------$:0\n");
                printf("道具描述:请我免费吃面包？天下哪有这等好事？总感觉怪怪的。\n");
                printf("\n");
                printf("2.🍑桃----------------------------$:15\n");
                printf("道具描述：蒸蒸日上！蒸！\n");
                printf("\n");
                printf("3.💊金疮药------------------------$:25\n");
                printf("道具描述：只在小说里听说过，真的存在么？\n");
                printf("\n");
                printf("4.🥤大力水------------------------$:30\n");   
                printf("道具描述：听说有人喝过之后，一天不喝浑身难受。\n");
                printf("\n");
                printf("5.🥃圣水--------------------------$:48\n");
                printf("道具描述：这东西...不知道从哪里来的。\n");
                printf("\n");          
                printf("6.🥗女朋友做的饭-------------------$:99\n");
                printf("道具描述：令人望眼欲穿的稀世珍品\n");
                printf("\n");
                printf("7.没事，我就随便看看。\n");
            }
                int medicamentchoice =0;
                scanf("%d",&medicamentchoice);
                switch(medicamentchoice)
                {
                    case 1:     //奇怪的面包
                        {   p->Gold=0;
                            system("clear"); 
                            printf("你零元购了一个[🍞奇怪的面包]并吃了下去。\n");
                            sleep(2);
                            system("clear");
                            printf(".......\n");
                            sleep(2);
                            system("clear");
                            printf("你昏睡了过去，再睁眼已经是第二天，不知道昨天晚上发生了什么.\n");
                            printf("你摸了摸兜...我靠！兜里一分钱也不剩。\n");
                            sleep(2);
                            system("clear");
                        return;
                        }
                    case 2:    //桃 
                        if(p->Gold<15)
                            {  
                            system("clear");
                            printf("你看了看价格，又摸了摸兜里的金币，想想还是算了吧。\n");
                            break;
                            }
                        else
                            {
                            p->Gold-=15;
                            p->backpack.InsertArrayTail(&p->backpack,CreateProp(MEDICAMENT,CreateMedicament("桃",10,-1)));
                            system("clear"); 
                            printf("你花费15金币购买了[🍑桃]。蒸！\n");
                            printf("你算了一下，兜里还有%d个金币。\n",p->Gold);
                            printf("\n");
                            sleep(2);
                            system("clear");
                            }
                        break;
                    case 3:     //金疮药
                        if(p->Gold<25)
                            {  
                            system("clear");
                            printf("你看了看价格，又摸了摸兜里的金币，想想还是算了吧。\n");
                            break;
                            }
                        else
                            {
                            p->Gold-=25;
                            p->backpack.InsertArrayTail(&p->backpack,CreateProp(MEDICAMENT,CreateMedicament("金疮药",15,-1)));
                            system("clear"); 
                            printf("你花费25金币购买了[💊金疮药]。\n");
                            printf("只有在古书里听说过的神乎其神的金疮药,真的有用么?\n");
                            printf("你算了一下，兜里还有%d个金币。\n",p->Gold);
                            printf("\n");
                            sleep(2);
                            system("clear");
                            }
                        break;

                    case 4:     //大力水
                        if(p->Gold<30)
                            {
                            system("clear");  
                            printf("你看了看价格，又摸了摸兜里的金币，想想还是算了吧。\n");
                            break;
                            }
                        else
                            {
                            p->Gold-=30;
                            p->backpack.InsertArrayTail(&p->backpack,CreateProp(MEDICAMENT,CreateMedicament("大力水",20,-1)));
                            system("clear"); 
                            printf("你花费30金币购买了[🥤大力水]。\n");
                            printf("你感到精神振奋,浑身充满了力量。我要买大力!!!\n");
                            printf("你算了一下，兜里还有%d个金币。\n",p->Gold);
                            printf("\n");
                            sleep(2);
                            system("clear");
                            }
                                
                        break;

                    case 5:     //圣水
                        if(p->Gold<48)
                            {  
                            system("clear");
                            printf("你看了看价格，又摸了摸兜里的金币，想想还是算了吧。\n");
                            break;
                            }
                        else
                            {
                            p->Gold-=48;
                            p->backpack.InsertArrayTail(&p->backpack,CreateProp(MEDICAMENT,CreateMedicament("圣水",30,-1)));
                            system("clear"); 
                            printf("你花费48金币购买了[🥃圣水]。\n");
                            printf("圣水?闻起来有种熟悉的味道。\n");
                            printf("你算了一下，兜里还有%d个金币。\n",p->Gold);
                            printf("\n");
                            sleep(2);
                            system("clear");
                            }
                        break;
                    
                    case 6:     //女朋友做的饭
                        if(p->Gold<99)
                            {  
                            system("clear");
                            printf("你看了看价格，又摸了摸兜里的金币，想想还是算了吧。\n");
                            break;
                            }
                        else
                            {
                            p->Gold-=99;
                            p->backpack.InsertArrayTail(&p->backpack,CreateProp(MEDICAMENT,CreateMedicament("女朋友做的饭",50,-1)));
                            system("clear"); 
                            printf("你花费99金币购买了[🥗女朋友做的饭]。\n");
                            printf("嗯~ shandy eat bee ei~\n");
                            printf("你算了一下，兜里还有%d个金币。\n",p->Gold);
                            printf("\n");
                            sleep(2);
                            system("clear");
                            }
                        break;
                    
                    default:
                        break;
                }
            medicamentchoice=0; 
            break;
        }
    
        //退出商店
            case 4:
        {
                system("clear");
                printf("谢谢光临!前路凶险,祝你好运~👋\n");
                sleep(2);
                system("clear");
            return;

            default:
                system("clear");
            return;
        }
        
    }
    choice =0;
    system("clear");
    }

}  


